package panda.client;

import com.google.gwt.user.client.Element;

/**
 * Modular collection of JSNI methods =P
 * 
 * @author zane.tian@gmail.com
 */
public class JSNI {
	public static native double getCurrentMs() /*-{
		var d = new Date();
		var time = d.getTime();
		return time;
	}-*/;
	
	public static native String getBrowserString() /*-{ 
	  var ua = navigator.userAgent.toLowerCase();
	  return ua;
	  }-*/;

	public static native void disableSelection(Element element) /*-{
	  	element.onselectstart = function() {
	  		return false;
	  	};
	  
	  	element.unselectable = "on";
	  	element.style.MozUserSelect = "none";
	}-*/;

	/** testing: from http://www.howtocreate.co.uk/tutorials/javascript/browserwindow */
	public static native int getScrollY() /*-{
		  var scrOfX = 0, scrOfY = 0;
		  if( typeof( window.pageYOffset ) == 'number' ) {
		    //Netscape compliant
		    scrOfY = window.pageYOffset;
		    scrOfX = window.pageXOffset;
		  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		    //DOM compliant
		    scrOfY = document.body.scrollTop;
		    scrOfX = document.body.scrollLeft;
		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		    //IE6 standards compliant mode
		    scrOfY = document.documentElement.scrollTop;
		    scrOfX = document.documentElement.scrollLeft;
		  }
		  return scrOfY;
	}-*/;

	/** testing: from http://www.howtocreate.co.uk/tutorials/javascript/browserwindow */
	public static native int getScrollX() /*-{
		  var scrOfX = 0, scrOfY = 0;
		  if( typeof( window.pageYOffset ) == 'number' ) {
		    //Netscape compliant
		    scrOfY = window.pageYOffset;
		    scrOfX = window.pageXOffset;
		  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		    //DOM compliant
		    scrOfY = document.body.scrollTop;
		    scrOfX = document.body.scrollLeft;
		  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		    //IE6 standards compliant mode
		    scrOfY = document.documentElement.scrollTop;
		    scrOfX = document.documentElement.scrollLeft;
		  }
		  return scrOfX;
	}-*/;
}